﻿/*  <Visual PureBasic IDE - a powerful tool to create PureBasic applications>
    Copyright (C) <2008>  <lanman>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
                                                                         */

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Security;

namespace VisualPureBasicIDE.CoreGUI
{
    static class Program
    {
        // Fast(!) (unsafe) windows API function.
        [SuppressUnmanagedCodeSecurity]
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static unsafe extern int MessageBox(IntPtr hWnd, String text, String caption, MessageBoxOptions options);

        /// <summary>
        /// The main entry point for Visual PureBasic IDE.
        /// </summary>
        [STAThread]
        [LoaderOptimization(LoaderOptimization.SingleDomain)]
        static unsafe void Main()
        {
            MessageBox(IntPtr.Zero, "Welcome to Visual PureBasic IDE! Please report all bugs you may encounter and please note that this program is still in alpha-state!", "Welcome!", (MessageBoxOptions) MessageBoxIcon.Information);

            // Subscribe to deal with unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(ApplicationManager.MainForm);
        }

        static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var ex = (Exception)e.ExceptionObject;

            var exceptionForm = new UnhandledVpbideExceptionForm(ex);
            exceptionForm.ShowDialog();
        }
    }
}